//package com.yihaodian.search.facet.converter;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//
//import com.browseengine.bobo.api.BrowseFacet;
//import com.browseengine.bobo.api.BrowseRequest;
//import com.browseengine.bobo.api.BrowseResult;
//import com.browseengine.bobo.api.FacetAccessible;
//import com.browseengine.bobo.api.FacetSpec;
//import com.browseengine.bobo.api.FacetSpec.FacetSortSpec;
//import com.browseengine.bobo.facets.FacetHandler;
//import com.browseengine.bobo.facets.impl.SimpleFacetHandler;
//import com.yihaodian.api.facet.FacetNode;
//import com.yihaodian.api.facet.FacetResult;
//import com.yihaodian.api.facet.SearchFacetSpec;
//import com.yihaodian.api.search.SearchRequest;
//import com.yihaodian.api.search.shard.ShardSearchRequest;
//import com.yihaodian.search.query.converter.QueryConverter;
//
//public class FacetConvertor {
//
//	public static BrowseRequest convertToReq(ShardSearchRequest shardSearchReq){
//		BrowseRequest br=new BrowseRequest();
//		SearchRequest req = shardSearchReq.getSearchRequest();
//		Map<String, SearchFacetSpec> facetSpecMap = req.getFacetSpecMap();
//		
//		// Set FacetSpec
//		Iterator<String> facetIt = facetSpecMap.keySet().iterator();
//		while (facetIt.hasNext()) {
//			String facetName = facetIt.next();
//			SearchFacetSpec searchFacetSpec = facetSpecMap.get(facetName);
//			FacetSpec facetSpec = new FacetSpec();
//			switch (searchFacetSpec.getOrderBy()) {
//			case SearchFacetSpec.ORDER_HIT_DESC:
//				facetSpec.setOrderBy(FacetSortSpec.OrderHitsDesc);
//				break;
//			case SearchFacetSpec.ORDER_LABEL_ASC:
//				facetSpec.setOrderBy(FacetSortSpec.OrderValueAsc);
//				break;
//			}
//			
//			br.setFacetSpec(facetName, facetSpec);
//		}
//		
//		// Set Query
//		if (req.getQuery() != null) {
//			try {
//				br.setQuery(QueryConverter.convert(req.getQuery()));
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//			
//		}
//		
//		return br;
//	}
//	
//	public static List<FacetHandler<?>> convertToHandlers(ShardSearchRequest shardSearchReq){
//		ArrayList<FacetHandler<?>> handlers = new ArrayList<FacetHandler<?>>();
//		Iterator<String> it = shardSearchReq.getSearchRequest().getFacetSpecMap().keySet().iterator();
//		while (it.hasNext()) {
//			String name = it.next();
//			handlers.add(new SimpleFacetHandler(name));
//		}
//		return handlers;
//	}
//	
//	public static Map<String, FacetResult> convertToFacetRes(BrowseResult browseRes){
//		Map<String, FacetResult> resultMap = new HashMap<String, FacetResult>();
//		
//		/**
//		 * Iterator the Browse facetReslutMap and convert it to our FacetResult.
//		 */
//		Map<String,FacetAccessible> facetMap = browseRes.getFacetMap();
//		Iterator<String> resultIt = facetMap.keySet().iterator();
//		while (resultIt.hasNext()) {
//			String name = resultIt.next();
//			FacetAccessible facet = facetMap.get(name);
//			
//			FacetResult facetRes = new FacetResult();
//			facetRes.nodes = new ArrayList<FacetNode>();
//			for (BrowseFacet facetValue : facet.getFacets()) {
//				FacetNode fn = new FacetNode(facetValue.getValue(),
//						facetValue.getFacetValueHitCount());
//				facetRes.nodes.add(fn);
//			}
//			
//			resultMap.put(name, facetRes);
//		}
//		return resultMap;
//	}
//}
